package com.bbx.demo.grpc.server;


import com.bbx.demo.grpc.server.impl.RouteService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class GrpcServer {

    /**
     * 创建 Grpc 服务
     * As you can see, we build and start our server using a ServerBuilder.
     * To do this, we:
     * 1、Specify the address and port we want to use to listen for client requests using the builder’s forPort() method.
     * 2、Create an instance of our service implementation class RouteGuideService and pass it to the builder’s addService() method.
     * 3、Call build() and start() on the builder to create and start an RPC server for our service.
     * @param args
     * @throws IOException
     * @throws InterruptedException
     */
    public static  void  main(String [] args) throws IOException, InterruptedException {

        Server server = ServerBuilder.forPort(8099).addService(new RouteService()).build().start();
        log.info("Server start .......");
        //使线程阻塞，不设置服务启动后就会停止
        server.awaitTermination();

    }
}
